﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class ForumMembers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.ForumMembers_PageTitle;
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            OnlineUser ou = (OnlineUser)Session["User"];
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            
            if (Request.QueryString["Answer"] != null)
                this.MessageLabel.Text = Request.QueryString["Answer"].ToString();
            
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");

            string ForumId = null;
            if (Request.QueryString["ForumId"] != null)
                ForumId = Request.QueryString["ForumId"].ToString();
            else
                Response.Redirect("~/ForumHomePage.aspx");
            
            if (GND.ReadNivdalBoolData("@ForumId", "Nivdal_ForumIsForumPublic", ForumId))
                Response.Redirect("~/ForumHomePage.aspx");
            if (!GND.ReadNivdalBoolData("@UserId ", "@ForumId", "Nivdal_ForumIsUserForumMember", ou.UserId, ForumId))
                Response.Redirect("~/ForumHomePage.aspx");
            this.BackToTheForumHyperLink.NavigateUrl = "ForumDetails.aspx?Id=" + ForumId;

            if (!IsPostBack)
            {
                this.ForumMembersSqlDataSource.SelectParameters.Add("ForumId", ForumId);
                this.ForumMembersSqlDataSource.SelectParameters.Add("Language", ou.Language);
            }
            string MembershipType = GND.ReadNivdalStringData("@UserId ", "@ForumId", "Nivdal_ForumGetMembershipType", ou.UserId, ForumId);
            if (MembershipType == "1")
            {
                this.AdministratorRoleHyperLink.Visible = true;
                this.AdministratorRoleHyperLink.Text = Resources.Resource.ForumMembers_ForumAdministratorApply;
                this.AdministratorRoleHyperLink.NavigateUrl = "ApplyForforumAdmin.aspx";
            }

            if (MembershipType == "2")
            {
                this.AdministratorRoleHyperLink.Visible = true;
                this.AdministratorRoleHyperLink.Text = Resources.Resource.ForumMembers_ForumAdministratorposition;
                string Answer = GND.ReadNivdalStringData("@UserId", "@ForumId", "Nivdal_ForumResignFromForumAdminPosition", ou.UserId, ForumId);
                this.AdministratorRoleHyperLink.NavigateUrl = "ForumMembers.aspx?Answer=" + Answer;
            }

            this.ForumNameLinkButton.Text = GND.ReadNivdalStringData("ForumId", "Nivdal_ForumGetForumName", ForumId);
            this.ForumNameLinkButton.NavigateUrl = "ForumDetails.aspx?Id=" + ForumId;

        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}